/************************************************************************************************
 * test examples of 100 interesting program in C
 * test 047.c
 * original program of test 047 in the book
 ***********************************************************************************************/

#include <stdio.h>
#include <string.h>

/*
 * the logic of this program is not totally wrong,
 * but remainder array is not large enough
 * bcz the remainder can be any number less than numerator
 */

int main()
{
	int remainder[101];
	int quotient[101];
	memset(remainder, 0, sizeof(int)*101);

	int m, n, i, j;
	printf("Plz input a fraction (m/n): ");
	scanf("%d/%d", &m, &n);
	printf("%d/%d = 0.", m, n);

	for (i = 1; i <= 100; i++)
	{
		// printf("[%d]", m);
		remainder[m] = i;
		m *= 10;
		quotient[i] = m/n;
		m = m%n;
		if (m == 0)
		{
			for (j = 1; j <= i; j++) printf("%d", quotient[j]);
			break;
		}
		if (remainder[m] != 0)
		{
			// printf("=[%d]", m);
			for (j = 1; j <= i; j++) printf("%d", quotient[j]);
			break;
		}
	}
	printf("\n");
}

